package test.format_test;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;


public class ForReflection {
    public static void main(String[] args) throws Exception{
        m1();
        m2();
        m3();
    }
    static void m1(){
        long t1 = System.currentTimeMillis();
        RTest r = new RTest();
        for(int i = 0;i<900000000;i++){
            r.hi();
        }
        System.out.println(System.currentTimeMillis()-t1);
    }
    static void m2() throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
        Class cls =Class.forName("test.format_test.RTest");
        Object o = cls.newInstance();
        Method m = cls.getMethod("hi");
        long t1 = System.currentTimeMillis();
        for(int i = 0;i<900000000;i++){
            m.invoke(o);
        }
        System.out.println(System.currentTimeMillis()-t1);
    }
    static void m3() throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
        Class cls =Class.forName("test.format_test.RTest");
        Object o = cls.newInstance();
        Method m = cls.getMethod("hi");
        m.setAccessible(true);
        long t1 = System.currentTimeMillis();
        for(int i = 0;i<900000000;i++){
            m.invoke(o);
        }
        System.out.println(System.currentTimeMillis()-t1);
    }
}


class RTest{
    public static void main(String[] args) throws ClassNotFoundException {
        Class cls = Class.forName("test.format_test.ForReflection");
        ClassLoader loader = cls.getClassLoader();
        Class clsnew = loader.loadClass("test.format_test.NewClass");
        System.out.println(clsnew);
    }
    public void hi(){
    }
}

class NewClass{
    public static void main(String[] args) {

    }
}